package com.hot100;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution209 {
    public int minSubArrayLen(int target, int[] nums) {
        int min = Integer.MAX_VALUE;
        int i = 0, j = 0, sum = 0;
        while (i < nums.length) {
            sum += nums[i];
            while (j <= i && sum >= target) {
                min = Math.min(i - j + 1, min);
                sum -= nums[j++];
            }
            i++;
        }
        return min == Integer.MAX_VALUE ? 0 : min;
    }
}
